package com.ys.web.ws.bean;

import com.ys.base.BaseBean;
import com.ys.base.BaseConstants;
import com.ys.base.EnumType;
import com.ys.utils.base.j2se.DateUtil;
import com.ys.utils.base.j2se.StringHandler;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @ 名称:请求消息对象
 * @ 创建人: dhf
 * @ 参数： null
 * @ 创建时间: 2022/5/11
 * @ 修改人和其它信息
 * @ 返回值:
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class MessageRequestBean extends BaseBean {

    /**
     * 消息id
     */
    public String messageId;

    /**
     * 消息类型
     */
    public Integer code;

    /**
     * 谁发送的消息
     */
    public String from;

    /**
     * 发送者的名称
     */
    public String userName;

    /**
     * 发送者的头像
     */
    public String avatarUrl;

    /**
     * 发送给谁
     */
    public String to;

    /**
     * 用户等级
     */
    public String level;
    /**
     * 组消息
     */
    public String groupId;

    /**
     * 消息
     */
    public String data;

    /**
     *
     */
    public String createTime;

    public double width;

    public double height;

    /**
     * 语音时间
     */
    public String soundSeconds;

    public String toMembers;

    public int payChannel;

    public long idKey = StringHandler.getLong(String.format("%s%s",System.currentTimeMillis(),(int)(Math.random()*899999+100000)));

    /**
     * @ 名称:消息对象
     * @ 创建人: dhf
     * @ 参数： null
     * @ 创建时间: 2022/5/11
     * @ 修改人和其它信息
     * @ 返回值:
     */
    public String validateParam(MessageRequestBean messageRequestBean, String type) {
        if (messageRequestBean == null) {
            return "参数传递错误";
        }
        if (messageRequestBean.getCode() == null || messageRequestBean.getCode() == 0) {
            return "请填写消息类型";
        }
        if (StringHandler.isEmpty(messageRequestBean.getMessageId())) {
            return "消息唯一标识必填";
        }
        if (StringHandler.isEmpty(messageRequestBean.getFrom())) {
            return "消息发起人必填";
        }
        if (StringHandler.isEmpty(messageRequestBean.getUserName())) {
            return "消息发起人名称必填";
        }
        if (StringHandler.isEmpty(messageRequestBean.getAvatarUrl())) {
            return "消息发起人头像必填";
        }
        if (StringHandler.isEmpty(messageRequestBean.getData())) {
            return "消息必填";
        }
        if (messageRequestBean.getCode().equals(EnumType.MessageCode.MESSAGE_SOUNDS.getCode()) && StringHandler.isEmpty(messageRequestBean.getSoundSeconds())) {
            return "语音时间必填";
        }
        if (type.equals(BaseConstants.MessageConstants.MESSAGE_USER) && StringHandler.isEmpty(messageRequestBean.getTo())) {
            return "消息接收人必填";
        }
        if (type.equals(BaseConstants.MessageConstants.MESSAGE_GROUP) && StringHandler.isEmpty(messageRequestBean.getGroupId())) {
            return "组 ID 必填";
        }
        if(messageRequestBean.getCreateTime().contains("上午") || messageRequestBean.getCreateTime().contains("下午")){
//            return "版本有误 请联系客服确认信息";
            messageRequestBean.setCreateTime(DateUtil.getDate(new Date(),BaseConstants.BASE_FORMAT));
        }
        messageRequestBean.setCreateTime(DateUtil.getDatetime());
        return null;
    }

    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public String getSoundSeconds() {
        return soundSeconds;
    }

    public void setSoundSeconds(String soundSeconds) {
        this.soundSeconds = soundSeconds;
    }

    public String getToMembers() {
        return toMembers;
    }

    public void setToMembers(String toMembers) {
        this.toMembers = toMembers;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public int getPayChannel() {
        return payChannel;
    }

    public void setPayChannel(int payChannel) {
        this.payChannel = payChannel;
    }


}
